/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.servinf.ani.sincronizador.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author mortiz
 */
public class PropertiesHelper {
    
    private static Properties properties;
    
    private static PropertiesHelper instance;

    /**
     * @return the properties
     */
    public Properties getProperties() {
        return properties;
    }
    
    private PropertiesHelper() {
        properties = new Properties();
        loadProperties();
    }
    
    public static PropertiesHelper getInstance() {
        if(instance == null) {
            instance = new PropertiesHelper();
        }
        return instance;
    }
    
  //public static void loadPropertiesFromClasspath(){
    public static void loadProperties() {
    	InputStream input = null;
    	try {
    		String filename = "application-config.properties";
    		input = PropertiesHelper.class.getClassLoader().getResourceAsStream(filename);
    		if(input==null){
    	            System.out.println("Sorry, unable to find " + filename);
    		    return;
    		}
                
    		//load a properties file from class path, inside static method
    		properties.load(input);

    	} catch (IOException ex) {
    		ex.printStackTrace();
        } finally{
        	if(input!=null){
        		try {
				input.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
        	}
        }
    }
    
    
}
